package continuum.db.schema.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import continuum.db.schema.embeddables.ContactInformation;
import continuum.db.schema.embeddables.SecurityDetails;

@Entity(name = "employee")
public class Employee implements Serializable {

	/**
	 * Serial version UID.
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Embedded
	private SecurityDetails securityDetails;

	@Embedded
	private ContactInformation contactInformation;

	@ManyToOne(targetEntity = Company.class, optional = false)
	@JoinColumn(name = "company_id", nullable = false)
	private Company company;

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "employee_task_map", joinColumns = { @JoinColumn(name = "employee_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(table = "task", name = "task_id", referencedColumnName = "id") })
	private List<Task> authorizedTasks = new ArrayList<Task>();

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public SecurityDetails getSecurityDetails() {
		return securityDetails;
	}

	public void setSecurityDetails(SecurityDetails securityDetails) {
		this.securityDetails = securityDetails;
	}

	public ContactInformation getContactInformation() {
		return contactInformation;
	}

	public void setContactInformation(ContactInformation contactInformation) {
		this.contactInformation = contactInformation;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public List<Task> getAuthorizedTasks() {
		return authorizedTasks;
	}

	public void setAuthorizedTasks(List<Task> authorizedTasks) {
		this.authorizedTasks = authorizedTasks;
	}

	public String getFullName() {
		return this.getContactInformation().getFirstName() + " "
				+ this.getContactInformation().getLastName();
	}

}
